Skip to content

fix: linear_focused attention dimension mismatches in v_map_mlp and final_linear - #5

Merged
HirenMadhu merged 1 commit into
Graph-and-Geometric-Learning:mainfrom
maximbeekenkamp:fix/linear-focused-dims
Jul 24, 2026
Merged

fix: linear_focused attention dimension mismatches in v_map_mlp and final_linear#5
HirenMadhu merged 1 commit into
Graph-and-Geometric-Learning:mainfrom
maximbeekenkamp:fix/linear-focused-dims

Conversation

@maximbeekenkamp

Copy link
Copy Markdown
Contributor

Summary

Two dimension bugs in LorentzMultiheadAttention when attention_type="linear_focused":

  1. v_map_mlp maps from in_channels - 1 to out_channels, but in the linear-focused path it receives v = hyp_vs[..., 1:] whose last dimension is out_channels - 2 (when use_weight=True). The result is added to attn_output which also has dimension out_channels - 2, so both the input and output of v_map_mlp must match that width.

  2. When trans_heads_concat=True, final_linear input width is num_heads * out_channels, but the concatenated linear-focused output has width num_heads * (out_channels - 2). The reshape in linear_focus_attention also hardcodes the wrong concat dimension.

Both bugs cause a RuntimeError on any valid input to the linear_focused path. The full attention path is unaffected.

Scope

Code-only fix for the two dimension bugs I was running into. Does not change the linear-attention formulation itself.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two shape/width mismatches in LorentzMultiheadAttention’s attention_type="linear_focused" code path so the value-side MLP and the head-concatenation projection (final_linear) align with the actual [..., 1:] (space-only) tensor widths used by linear-focused attention. This prevents runtime dimension errors while leaving the full attention path unchanged.

Changes:

  • Adjust v_map_mlp to map within the correct “v-space” width (out_channels - 2 when use_weight=True, otherwise out_channels - 1) to match v = hyp_vs[..., 1:] and attn_output.
  • Make final_linear’s input width conditional on linear_focused so it matches the concatenated linear-focused output width.
  • Fix the reshape feeding final_linear in linear_focus_attention to avoid hardcoding num_heads * out_channels and preserve the sequence length dimension.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@HirenMadhu
HirenMadhu merged commit 73948db into Graph-and-Geometric-Learning:main Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants